// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PATIENT_PPT_PCL : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("8 PID",8)]
  	    [HL7Field(HL7Version.v23, 8, HL7Repeat.False, HL7Required.True,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("9 PATIENT_VISIT",9)]
  	    [HL7Field(HL7Version.v23, 9, HL7Repeat.False, HL7Required.False,"PATIENT_VISIT_PPT_PCL")]
	    public PATIENT_VISIT_PPT_PCL PATIENT_VISIT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("15 PATHWAY",15)]
  	    [HL7Field(HL7Version.v23, 15, HL7Repeat.True, HL7Required.True,"PATHWAY_PPT_PCL")]
	    public PATHWAY_PPT_PCL[] PATHWAY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("37 GOAL",37)]
  	    [HL7Field(HL7Version.v23, 37, HL7Repeat.False, HL7Required.False,"GOAL_PPT_PCL")]
	    public GOAL_PPT_PCL GOAL {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("60 GOAL_OBSERVATION",60)]
  	    [HL7Field(HL7Version.v23, 60, HL7Repeat.False, HL7Required.False,"GOAL_OBSERVATION_PPT_PCL")]
	    public GOAL_OBSERVATION_PPT_PCL GOAL_OBSERVATION {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
			PATIENT_VISIT = ProcessGroup<PATIENT_VISIT_PPT_PCL>(availableData, options, "PATIENT_VISIT");
			PATHWAY = ProcessGroupArray<PATHWAY_PPT_PCL>(availableData, options, "PATHWAY");
			GOAL = ProcessGroup<GOAL_PPT_PCL>(availableData, options, "GOAL");
			GOAL_OBSERVATION = ProcessGroup<GOAL_OBSERVATION_PPT_PCL>(availableData, options, "GOAL_OBSERVATION");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPID = availableData.StartsWith("PID", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PID", options.Version) || isPID) {
				return isPID;
			}
			PATIENT_VISIT_PPT_PCL testPATIENT_VISIT_PPT_PCL = new PATIENT_VISIT_PPT_PCL();
			bool grpCCPATIENT_VISIT_PPT_PCL = (testPATIENT_VISIT_PPT_PCL.CanConsume(availableData, options));
			if (IsRequired("PATIENT_VISIT", options.Version) || grpCCPATIENT_VISIT_PPT_PCL) {
				return grpCCPATIENT_VISIT_PPT_PCL;
			}
			PATHWAY_PPT_PCL testPATHWAY_PPT_PCL = new PATHWAY_PPT_PCL();
			bool grpCCPATHWAY_PPT_PCL = (testPATHWAY_PPT_PCL.CanConsume(availableData, options));
			if (IsRequired("PATHWAY", options.Version) || grpCCPATHWAY_PPT_PCL) {
				return grpCCPATHWAY_PPT_PCL;
			}
			GOAL_PPT_PCL testGOAL_PPT_PCL = new GOAL_PPT_PCL();
			bool grpCCGOAL_PPT_PCL = (testGOAL_PPT_PCL.CanConsume(availableData, options));
			if (IsRequired("GOAL", options.Version) || grpCCGOAL_PPT_PCL) {
				return grpCCGOAL_PPT_PCL;
			}
			GOAL_OBSERVATION_PPT_PCL testGOAL_OBSERVATION_PPT_PCL = new GOAL_OBSERVATION_PPT_PCL();
			bool grpCCGOAL_OBSERVATION_PPT_PCL = (testGOAL_OBSERVATION_PPT_PCL.CanConsume(availableData, options));
			if (IsRequired("GOAL_OBSERVATION", options.Version) || grpCCGOAL_OBSERVATION_PPT_PCL) {
				return grpCCGOAL_OBSERVATION_PPT_PCL;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PATIENT";
			}
        }

        static PATIENT_PPT_PCL() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PATIENT_PPT_PCL));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PID != null) {
			string segmentValue = PID.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PATIENT_VISIT != null) {
			string segmentValue = PATIENT_VISIT.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PATHWAY != null && PATHWAY.Length > 0) {
			for (int i = 0; i < PATHWAY.Length; i++) {
				string segmentValue = PATHWAY[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (GOAL != null) {
			string segmentValue = GOAL.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (GOAL_OBSERVATION != null) {
			string segmentValue = GOAL_OBSERVATION.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

